package com.slz3.business.module.systemManagement.sysUser.steward;

import com.slz3.business.frame.response.RR;
import com.slz3.business.frame.response.ResInfo;
import com.slz3.business.frame.util.Md5Utils;
import com.slz3.business.frame.util.UUIDUtils;
import com.slz3.business.module.systemManagement.sysUser.domain.SysUser;
import com.slz3.business.module.systemManagement.sysUser.domain.SysUserCondition;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

import java.util.UUID;

public class SysUserResAtomic {

    static Mono<ServerResponse> add_$SysUserUpdateLock(ServerRequest req, SysUser sysUser) {
        dealWithSerPass(sysUser);
        return SysUserResSafeValid.add(req, sysUser) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.add(req, sysUser);
    }

    public static Mono<ServerResponse> delete_$SysUserUpdateLock(ServerRequest req, SysUserCondition sysUserCondition) {
        return SysUserResSafeValid.delete(req, sysUserCondition) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.delete(req);
    }

    static Mono<ServerResponse> modify_$SysUserUpdateLock(ServerRequest req, SysUser sysUser) {
        dealWithSerPass(sysUser);
        return SysUserResSafeValid.modify(req, sysUser) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.modify(req, sysUser);
    }

    static Mono<ServerResponse> info_$SysUserUpdateLock(ServerRequest req) {
        return SysUserResSafeValid.info(req) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.info(req);
    }

    public static Mono<ServerResponse> auditSubmit_$SysUserUpdateLock(ServerRequest req, SysUserCondition sysUserCondition) {
        return SysUserResSafeValid.auditSubmit(req, sysUserCondition) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.auditSubmit(req);
    }

    public static Mono<ServerResponse> audit_$SysUserUpdateLock(ServerRequest req, SysUserCondition sysUserCondition) {
        return SysUserResSafeValid.audit(req, sysUserCondition) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.audit(req);
    }

    public static Mono<ServerResponse> auditReject_$SysUserUpdateLock(ServerRequest req, SysUserCondition sysUserCondition) {
        return SysUserResSafeValid.auditReject(req, sysUserCondition) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.auditReject(req);
    }


    public static Mono<ServerResponse> usingEnable_$SysUserUpdateLock(ServerRequest req, SysUserCondition sysUserCondition) {
        return SysUserResSafeValid.usingEnable(req, sysUserCondition) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.usingEnable(req);
    }

    public static Mono<ServerResponse> usingDisable_$SysUserUpdateLock(ServerRequest req, SysUserCondition sysUserCondition) {
        return SysUserResSafeValid.usingDisable(req, sysUserCondition) ?
                RR.fail(req, ResInfo.builder().theme(RR.SAFE_VALID).build()) :
                SysUserResExecutor.usingDisable(req);
    }

    private static void dealWithSerPass(SysUser sysUser) {
        UUID saltUuid = UUIDUtils.generateUUID();
        sysUser.setSaltUuid(saltUuid);
        sysUser.setSerPass(Md5Utils.encode(String.format("%s%s", sysUser.getSerPass(), saltUuid.toString())));
    }
}
